import os
import uvicorn
import sys
from fastapi import FastAPI
from starlette.middleware import Middleware
from lib import CustomMiddleware

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
app = FastAPI(
    title="demo",
    description="fastapi demo",
    middleware=[
        Middleware(CustomMiddleware)
    ]
)


def endpoint_register():
    """
    添加单点函数
    :return:
    """
    from endpoint import test
    app.add_api_route("/test", endpoint=test, tags=["测试endpoint"])


def router_register():
    """
    添加router
    :return:
    """
    from router import demo_router
    app.include_router(router=demo_router.router, tags=["测试router"])


endpoint_register()
router_register()

if __name__ == '__main__':
    # uvicorn.run(app=app)
    uvicorn.run(
        "fastapi_main:app",
        host="127.0.0.1",
        port=8000,
        log_level="info",
        access_log=True,
        use_colors=True,
        debug=False,
        reload=True,
    )
